package com.lxm.sevice.qq;

import com.alibaba.fastjson.JSONObject;
import com.lxm.action.ActionBase;
import com.lxm.dao.WxMapperDao;
import com.lxm.entity.ReturnMessage;
import com.lxm.entity.UserEntity;
import com.lxm.util.HttpUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * @author ：Administrator
 * @date :创建时间 2021/12/29 16:35
 */
@Service
public class QQServiceImpl implements QQService{
    @Value("${urlPath.queryQQUrl}")
    private String queryQQUrl;
    @Autowired
    private WxMapperDao wxMapperDao;

    @Override
    public String getFriend(String qqCode) {
        return null;
    }

    @Override
    public ReturnMessage addFriend(String flag, boolean approve, String remark) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("flag",flag);
        jsonObject.put("approve",approve);
        jsonObject.put("remark",remark);
        HttpUtils.post(queryQQUrl+"set_friend_add_request",jsonObject.toJSONString());
        return ActionBase.success();
    }

    public ReturnMessage isAddFriend( JSONObject jsonObject ){
        String comment = jsonObject.getString("comment");
        if(comment ==null|| comment.isEmpty()){
            return ActionBase.error("没有验证信息");
        }
        UserEntity userEntity = new UserEntity();
        userEntity.setAuthCode(comment);
        UserEntity userEntity1 = wxMapperDao.queryUserData(userEntity);
        if(null == userEntity1){
            addFriend(jsonObject.getString("flag"),false,"");
            return ActionBase.error("无该用户");
        }else {
            addFriend(jsonObject.getString("flag"),true,"");

        }
        return ActionBase.success("发送成功");
    }

}
